<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset=UTF-8"">
<title>店铺商品查询</title>
<link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap.min.css" />
<link rel="stylesheet" href="${contextPath}/static/bootstrap/css/bootstrap-table.css" />
<link rel="stylesheet" href="${contextPath}/static/ace/assets/css/ace.css" />
<link rel="stylesheet" href="${contextPath}/static/bootstrap/css/bootstrap-select.css" />
<link rel="stylesheet" href="${contextPath}/static/statistics/css/bootstrap-datetimepicker.min.css" />
<link rel="stylesheet" href="${contextPath}/static/ztree/css/zTreeStyle.css" />
<link rel="stylesheet" href="${contextPath}/static/layer/css/layui.css" />
<script src="${contextPath}/static/statistics/js/jquery.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap.min.js"></script>
<script src="${contextPath}/static/bootstrap/js/bootstrap-select.min.js"></script>
<script src="${contextPath}/static/bootstrap/js/defaults-zh_CN.min.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.fr.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js"></script>
<script src="${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js"></script>
<script src="${contextPath}/static/util/dateutils.js"></script>
<script src="${contextPath}/static/util/protutils.js"></script>
<script src=${contextPath}/static/layer/layui.all.js></script>
<style type="text/css">
	input.combo-input{
		padding:7px 4px; 
	}
	.panel{
		margin-bottom:0px;	
	}
	.bs-actionsbox .btn-group button {
	    width: 45%;
	}
	.bootstrap-select:not([class*="col-"]):not([class*="form-control"]):not(.input-group-btn) {
	    width: 100%;
	}	
	.list-group-item{
		padding:5px 6px;
		font-size:11px;
	}
	#zoneCode .list-group .list-group-item:first-child{
		padding:7px 6px;
	}
	.panel-heading::after {
	    content: "";
	    display: block;
	    clear: both;
	}
	.caret{
		color:#ABBAC3;
	}
	.bootstrap-select > .btn{
		color:#ABBAC3 !important;
		background-color: #fff !important;
		text-shadow:none;
		border-width:1px;
	}
	.bootstrap-select > .btn:hover, .bootstrap-select > .btn:focus:hover, .bootstrap-select > .btn.focus:hover, .bootstrap-select > .btn:active:hover, .bootstrap-select > .btn:focus:active, .btn-default:focus:active, .open > .btn.dropdown-toggle, .open > .btn-default.dropdown-toggle, .open > .btn.dropdown-toggle:hover, .open > .btn-default.dropdown-toggle:hover, .open > .btn.dropdown-toggle:focus, .open > .btn-default.dropdown-toggle:focus, .open > .btn.dropdown-toggle.focus, .open > .btn-default.dropdown-toggle.focus, .open > .btn.dropdown-toggle:active, .open > .btn-default.dropdown-toggle:active {
	    background-color: #fff !important;
	    border-color: #ABBAC3;
	}
	.fixed-table-footer{
	    overflow: auto;
	}
	.dropdown-header{
		cursor:pointer;
	}
	.clearfix:after {content:"."; display:block; height:0; visibility:hidden; clear:both; }	
	.breadcrumb > li + li:before {
	    color: #CCCCCC;
	    content: "";
	    padding: 0 5px;
	}
	.breadcrumb > li > label{
		margin-left:2px;
	}
	.zone-block{
		display: inline-block;
		color: #FFF !important;
		text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
		background-image: none !important;
		border-radius: 2px;
		box-shadow: none !important;
		-webkit-transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
		-o-transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
		transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
		cursor: pointer;
		vertical-align: middle;
		margin: 0;
		position: relative;
	}	
</style>
</head>
<body>
 <div class="panel panel-default" id="app">
 			<div class="panel-heading">
 				<h3 class="panel-title pull-left" style="text-shadow:2px 1px 2px #ABBAC3">店铺商品查询报表</h3>
 				<h5 class="pull-right" id="timeCount" style="margin-top: 0;margin-bottom: 0;"></h5>
 			</div>
            <div class="panel-body">
                <form class="form-horizontal" class="form-inline" style="margin-bottom: 5px;"
				action="${contextPath}/ktcount/exportExcelSellstocks" method="post" id="exportExcel">
                    <div class="form-group">
                        <div class="col-sm-2">
                            <input type="text" class="form-control" id="productName" name="productName" placeholder="请输入商品名称">
                        </div>
                        <div class="col-sm-2">
                        	<div class="input-group ">
                        		<input id="typeName" class="form-control" placeholder="选择商品类型" readonly/>
                        		<input id="typeId" name="prodType" type="hidden" />
                        		<input id="foreTypeName" name="foreTypeName" type="hidden" />
	                        	<span class="input-group-btn">
		                        	<div class="btn btn-primary btn-sm" onclick="javascript:$('#typeModal').modal('show');">
										选择
									</div>
	                        	</span>
                        	</div>
                        		                
						</div>
                        <div class="col-sm-2">
                            <select class="form-control" id="supplierId"  multiple title="选择供应商名称" data-live-search="true" data-live-search-placeholder="搜索" data-actions-box="true" >
							</select>
							<input type="hidden" name="supplierId" id="supplierid" />
                        </div>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" id="turnCreateDate" name="turnCreateDate" placeholder="查询开始时间" readonly />
                        </div>
                        <div class="col-sm-2">
							<input type="text" class="form-control" id="bindCreateDate" name="bindCreateDate" placeholder="查询结束时间" readonly />
                        </div>
                        
                    </div>
                    <div class="form-group">
                    	<div class="col-sm-2">
                            <input type="text" class="form-control" id="productCode" name="productCode" placeholder="请输入条码">
                        </div>
                        <div class="col-sm-3">
                        <label class="radio-inline">
						       	 查询类型
						    </label>
                        	<label class="radio-inline">
						        <input type="radio" name="typeRadio" value="0" checked /> 销售
						    </label>
							<label class="radio-inline">
						        <input type="radio" name="typeRadio" value="1" /> 库存
						    </label>
							<label class="radio-inline">
						        <input type="radio" name="typeRadio" value="2" /> 入库
						    </label>
						    
                        </div>
                       <div class="col-sm-2">
                        	<label class="radio-inline">
						        <input type="radio" name="tbRadio" value="1" checked /> 包
						    </label>
							<label class="radio-inline">
						        <input type="radio" name="tbRadio" value="0" /> 条
						    </label>
                        </div>
                    </div>
                    <div class="form-group ">
                    	
                        <div class="col-sm-3">
                        	<div class="input-group ">
                        		<input id="areaName" name="areaName" class="form-control" placeholder="选择区域" readonly/>
                        		<input id="areaCode" name="areaCode" type="hidden" />
	                        	<span class="input-group-btn">
		                        	<div class="btn btn-primary btn-sm" onclick="javascript:$('#areaModal').modal('show');">
										选择
									</div>
	                        	</span>
                        	</div>
                        		                
						</div>
						<div class="col-sm-2">
                             <select class="selectpicker" multiple data-live-search="true" title="请选择店铺名称" data-live-search-placeholder="搜索" data-actions-box="true" id="shopName">
								<optgroup label="直营" data-icon="glyphicon-ok">
									<c:forEach items="${shopnames}" var="shopname">
										<c:if test="${shopname.shopType=='直营'}">
											<option value="${shopname.shopId}">${shopname.shopName}</option>
										</c:if>
									</c:forEach>
								</optgroup>
								<optgroup label="加盟" data-icon="glyphicon-ok">
									<c:forEach items="${shopnames}" var="shopname">
										<c:if test="${shopname.shopType=='加盟'}">
											<option value="${shopname.shopId}">${shopname.shopName}</option>
										</c:if>
									</c:forEach>
								</optgroup>
							</select>
							<input type="hidden" name="shopName" id="shopname" />
							<input type="hidden" name="shopIdName" id="shopIdName" />
                        </div>
                    	<div class="col-sm-1" style="text-align:left;">
                            <button type="button"  id="btn_query" class="btn btn-sm btn-info">查询</button>
                        </div>
                    </div>
                    <input type="hidden" id="colsTitles" name="colsTitles" />
                    <input type="hidden" id="colsFields" name="colsFields" />
                </form>
            </div>

        <div  style="background-color:#e4e6e9;overflow:hidden">
             <div class="clearfix" style="margin:10px 15px 10px 15px;">
             	<div class="pull-left btn-group">
		 			<button id="btn_refresh" type="button" class="btn btn-sm btn-warning">
		                <span class="glyphicon glyphicon-refresh icon-refresh" aria-hidden="true"></span>刷新
		            </button>
		            <button onclick="exportExcel();" type="button" class="btn btn-sm btn-success">
		                <span class="glyphicon glyphicon-file" aria-hidden="true"></span>导出
		            </button>
		            <button onclick="doPrint();" type="button" class="btn btn-sm btn-default">
		                <span class="glyphicon glyphicon-print" aria-hidden="true"></span>打印
		            </button>
		            <button type="button" class="btn btn-sm btn-success"
						onclick="javascript:window.history.go(-2);window.close();">
						<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>返回</button>
				</div>
				<div class="pull-right btn-group">
					<ul class="breadcrumb">
					<li><a class="zone-block" style="background-color:#fff;padding:2px 8px;line-height:10px">&nbsp;</a><label id="lb1">0~10</label></li>
					<li><a class="zone-block" style="background-color:#fcff00;padding:2px 8px;line-height:10px">&nbsp;</a><label id="lb2">10~50</label></li>
					<li><a class="zone-block" style="background-color:#f00;padding:2px 8px;line-height:10px">&nbsp;</a><label id="lb3">50~∞</label></li>
					</ul>
				</div>
	        </div> 
	        <div class="table-responsive" id="tableContainer" style="height:500px">
        <table class="table table-striped table-condensed table-bordered">
			<thead id="cthead"></thead>
            <tbody id="ctbody">
<!--             <tr v-for="(obj, index) in sellstockList">
                <td v-for="(map, index) in obj" style="width: 100px;">
                    {{map}}
                   
                </td>
            </tr> -->
            </tbody>
        </table>
        <!--endprint-->
        </div>
    </div>
   </div>
  	<div id="areaModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="areaModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="areaModalLabel">
						选择区域
					</h4>
				</div>
				<div class="modal-body">
					<ul id="areatree" class="ztree">
					</ul>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-primary" onclick="javascript:selectedAreas()">
						确认
					</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消
					</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
			<div id="typeModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="typeModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="typeModalLabel">
						选择商品类型
					</h4>
				</div>
				<div class="modal-body">
					<ul id="typetree" class="ztree">
					</ul>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-primary" onclick="javascript:selectedTypes()">
						确认
					</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消
					</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
		</div> 
</body>
<script type="text/javascript">
	function getktSellstock(){
		if($("#btn_query").hasClass("btn-default"))
			return;
		$("#btn_query").removeClass("btn-info").addClass("btn-default");
		var shopName = $("#shopName").val() == null ? "-1":$("#shopName").val().join(",");
		var searchType = $("input[name='typeRadio']:checked").val();
		$.ajax({
			url: '${contextPath}/ktcount/getktSellstocks', //localhost:8080
	        type: 'post',
	        data:{
	            shopName : shopName,
		    	prodType : $("#typeId").val().trim(),
		    	productName : $("#productName").val().trim(),
		    	turnCreateDate :$("#turnCreateDate").val().trim(),
		    	bindCreateDate : $("#bindCreateDate").val().trim(),
		    	areaCode : $("#areaCode").val().trim(),
		    	productCode : $("#productCode").val().trim(),
		    	supplierId : $("#supplierid").val(),
		    	typeRadio: searchType,
		    	tbType: $("input[name='tbRadio']:checked").val()},
		    beforeSend:function(){
		    	$("#btn_query").removeClass("btn-info").addClass("btn-default");
		    	layer.msg('正在努力加载数据...', {icon: 16,time:0});
		    },
	        success: function (data) {
	        	$("#btn_query").removeClass("btn-default").addClass("btn-info");
	        	var sellstockLis = data.data;
	        	var htmlth="",htmltr = "";
	        	for(var i=0,sellstockLiLen = sellstockLis.length;i<sellstockLiLen;i++){
	        		if(i == 0){
	        			htmlth+= '<tr>';
		        		for(k in sellstockLis[i]){
		        			htmlth+='<th><div style="min-width: 100px;">'+sellstockLis[i][k]+'</div></th>'
		        		}
		        		htmlth+='</tr>'
		        		continue;
	        		}
	        		htmltr+= '<tr>';
	        		for(k in sellstockLis[i]){
	        			var backgroundStyle="";
	        			if(!("PROD_NAME" == k||"TSUM" == k|| i == (sellstockLiLen-1))){
	        				if(sellstockLis[i][k] >0 && sellstockLis[i][k] <= 10){
	        					backgroundStyle="background-color:#fff";
	        				}else if(sellstockLis[i][k] >10 && sellstockLis[i][k] <= 50){
	        					backgroundStyle="background-color:#fcff00";
	        				}else if(sellstockLis[i][k] >50){
	        					backgroundStyle="background-color:#f00";
	        				}
	        			}
	        			htmltr+='<td style="'+backgroundStyle+'" data-k="'+k+'" data-shop="'+sellstockLis[0][k]+'" data-prod="'+sellstockLis[i]["PROD_NAME"]+'"><div style="min-width: 100px;">'+sellstockLis[i][k]+'</div></td>'
	        		}
	        		htmltr+='</tr>'
	        	}
	        	$("#cthead").html(htmlth);
	        	$("#ctbody").html(htmltr);
	        	$("#tableContainer td").hover(tdHover)
	        	layer.closeAll();
	        }
		})
	}
	$(function(){
		$('#shopName').selectpicker('selectAll');
		getProdType();
		getArea();
		$('#supplierId').selectpicker();
		initDatetimepicker([ "turnCreateDate", "bindCreateDate" ])
		$(".dropdown-header").click(ddHeaderClick);
		$('#shopName').on('changed.bs.select',onSelectChange)
		timeCount();
	})
function getProdType(){
	$.ajax({
        url: '${contextPath}/ktcount/getProdTypes', //localhost:8080
        type: 'post',
        success: function (data) {
            var orginTypes = data.data;
            var setting = {
                    check: {
                        enable: true,
                        chkStyle: "checkbox",
                    },
                    data: {
                        simpleData: {
                            enable: true,
                            idKey: "TYPE_ID",
                            pIdKey: "PARENT_ID",
                            rootPId: ''
                        },
                        key: {
                            name: "TYPE_NAME"
                        },
                    },
                };
                $.fn.zTree.init($("#typetree"), setting, orginTypes);
                selectedTypes();
                getSupplier();
                getktSellstock();
        },
        error: function (error) {
            alert(error)
        }
    })
}
	function getSupplier(){
		$.ajax({
	        url: '${contextPath}/ktcount/getSuppliers', //localhost:8080
	        data:{"typeId":$("#typeId").val()},
	        type: 'post',
	        success: function (data) {
	           	var data = data.data;
	           	var html = "";
	        	for(var i = 0;i < data.length;i++){
	        		html +='<option value="'+data[i]["ID"]+'">'+data[i]["SUPPLIER_NAME"]+'</option>';
	        	}

	        	$("#supplierId").html(html);
	        	$('#supplierId').selectpicker('refresh');
	        	$("#supplierid").val("");
	        },
	        error: function (error) {
	            alert(error)
	        }
	    })
	}
function getArea(){
	$.ajax({
        url: '${contextPath}/ktcount/getAreas', //localhost:8080
        type: 'post',
        success: function (data) {
            var orginAreas = data.data;
            var setting = {
                    check: {
                        enable: true,
                        chkStyle: "checkbox",
                    },
                    data: {
                        simpleData: {
                            enable: true,
                            idKey: "ID",
                            pIdKey: "PARENT_ID",
                            rootPId: '',
                            areaCode:"ZONE_CODE"
                        },
                        key: {
                            name: "ZONE_NAME"
                        },
                    },
                };
                $.fn.zTree.init($("#areatree"), setting, orginAreas);
                
        },
        error: function (error) {
            alert(error)
        }
    })	
}
function getShop(){
	$.ajax({
        url: '${contextPath}/ktcount/getShops', //localhost:8080
        data:{"zoneCode":$("#areaCode").val()},
        type: 'post',
        success: function (data) {
           	var data = data.data;
			var dstore = '<optgroup label="直营" data-icon="glyphicon-ok">',nstore = '<optgroup label="加盟" data-icon="glyphicon-ok">';
        	for(var i = 0;i < data.length;i++){
        		if('直营' == data[i]["shopType"]){
        			dstore +='<option value="'+data[i]["shopId"]+'">'+data[i]["shopName"]+'</option>';
        		}
				if('加盟' == data[i]["shopType"]){
					nstore +='<option value="'+data[i]["shopId"]+'">'+data[i]["shopName"]+'</option>';
        		}
        	}
        	dstore += '</optgroup>';
        	nstore += '</optgroup>';
        	$("#shopName").html(dstore+nstore);
        	$('#shopName').selectpicker('refresh');
        	$('#shopName').selectpicker('selectAll');
        },
        error: function (error) {
            alert(error)
        }
    })
}
    function trans2FormatDate(date,isMonth){
		date.setDate(date.getDate());
		isMonth && date.setMonth(date.getMonth()-1);
		return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()
	}  
    $('#supplierId').on('changed.bs.select',function(e){
    	var supplierIds = $(this).val(),
			supplierId = "";
		if(supplierIds != null){
			for(var i=0;i<supplierIds.length;i++){
				supplierId +="\'"+supplierIds[i]+"\',"
			}
			supplierId = supplierId.substring(0,supplierId.length-1)
		}
		$("#supplierid").val(supplierId)
    });
    $("#btn_refresh").bind('click',function(){
    	if($("#btn_query").hasClass("btn-default")){
    		return;
    	}
    	$('#shopName').selectpicker('selectAll');
    	$('#supplierId').selectpicker();
    	$("#productName").val("");
    	$("#productCode").val("");
    	$("#turnCreateDate").val("");
    	$("#bindCreateDate").val("");
    	$("#areaCode").val("");
    	$("#supplierid").val("");
    	$("#areaName").val("");
    	//$('#zoneCode').treeview('clearSearch');
    	getktSellstock();
    }) 

$("#btn_query").bind("click",function(){
	getktSellstock();
})    
function selectedAreas(){
	 $("#areaModal").modal('hide')
     var zTree = $.fn.zTree.getZTreeObj("areatree");
     var nodes = zTree.getCheckedNodes();
     var areaNameVal = "",areaCodeVal = "";
     for(var i = 0,nodesLen = nodes.length;i < nodesLen;i++){
    	 if(!nodes[i]["isParent"]){
	    	 areaNameVal += nodes[i]["ZONE_NAME"]+",";
	    	 areaCodeVal += nodes[i]["ZONE_CODE"]+",";
    	 }
     }
     if(nodes.length > 0){
	    areaNameVal = areaNameVal.substring(0,areaNameVal.length-1);
	    areaCodeVal = areaCodeVal.substring(0,areaCodeVal.length-1);

     }
     $("#areaName").val(areaNameVal);
     $("#areaCode").val(areaCodeVal);
     getShop();
}
function selectedTypes(){
	 $("#typeModal").modal('hide')
    var zTree = $.fn.zTree.getZTreeObj("typetree");
    var nodes = zTree.getCheckedNodes();
    var typeNameVal = "",typeIdVal = "",foreTypeNameVal = "";
    for(var i = 0,nodesLen = nodes.length;i < nodesLen;i++){
   	 if(!nodes[i]["isParent"]){
	    	 typeNameVal += nodes[i]["TYPE_NAME"]+",";
	    	 typeIdVal += nodes[i]["TYPE_ID"]+",";
   	 }
   	 if(nodes[i]["level"] == 0){
   		 foreTypeNameVal += nodes[i]["TYPE_NAME"]+",";
   	 }
    }
    if(nodes.length > 0){
   	 typeNameVal = typeNameVal.substring(0,typeNameVal.length-1);
   	 typeIdVal = typeIdVal.substring(0,typeIdVal.length-1);
   	 foreTypeNameVal = foreTypeNameVal.substring(0,foreTypeNameVal.length-1);
    }
    $("#typeName").val(typeNameVal);
    $("#typeId").val(typeIdVal);
    $("#foreTypeName").val(foreTypeNameVal);
    getSupplier();
}
var exportExcel = function() {
	var shopName = $("#shopName").val() == null ? "\'\'":$("#shopName").val().join(",");
	$("#shopname").val(shopName);
	var shopIdName = $("[data-id='shopName']").attr("title");
	if(shopIdName.indexOf(",") == -1 && shopIdName!="选择商店名称"){
		$("#shopIdName").val(shopIdName);
	}
	$("#exportExcel").submit();
}
function initDatetimepicker(arr) {
	arr.forEach(function(item, index, input) {
		$('#' + item).datetimepicker({
			language : 'zh-CN',
			weekStart : 1,
			todayBtn : 1,
			todayHighlight : 1,
			startView : 3,
			forceParse : 0,
			showMeridian : 1,
			format : "yyyy-mm-dd",
			autoclose : true,
			minView : "month",
			initialDate:trans2FormatDate(new Date())
		}).on('changeDate', function(ev){
		    var idVal = $(this).attr("id");
		    var date = ev.date;
		    if(idVal == "turnCreateDate"){
		    	$("#turnCreateDate").val(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" 00:00:00")
		    }else{
		    	$("#bindCreateDate").val(date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate()+" 23:59:59")
		    }
		});
	})
	$('#turnCreateDate').val(trans2FormatDate(new Date(),false)+" 00:00:00")
	$('#bindCreateDate').val(trans2FormatDate(new Date(),false)+" 23:59:59")
}
function tdHover(){
	var shop = $(this).attr("data-shop"),prod = $(this).attr("data-prod"),k = $(this).attr("data-k");
	if("PROD_NAME" == k)
		return;
	var msg = "";
	if("合计" != shop)
		msg+="店铺:"+shop;
	else
		msg+="店铺合计";
	if("合计" != prod)
		msg+=",商品:"+prod;
	else
		msg+=",商品合计";
	layer.tips(msg, this, {
		  tips: [4], //还可配置颜色
		  time:5000
		})
}
function ddHeaderClick(e){
	var $span = $(this).children("span:first-child");
	var idVal = $(this).parent().parent().next().attr("id");
	var allSelected = $("#"+idVal).val() || [];
	var index = $(this).attr("data-optgroup")-1;
	var $groupOption = $("#"+idVal).find('optgroup').eq(index).find("option");
	$groupOption.each(function(index,element){
		if($span.hasClass("glyphicon-ok")){
			allSelected.remove($(this).val());
		}else{
			allSelected.push($(this).val())
		}
	})
	if($span.hasClass("glyphicon-ok")){
		$span.removeClass("glyphicon-ok")
	}else{
		$span.addClass("glyphicon-ok")
	}
	$("#"+idVal).selectpicker('val',allSelected)
}
function onSelectChange(e){
	var idVal = $(this).attr("id");
	var $ddHeader = $("#"+idVal).prev().find(".dropdown-header");
	var $optgroup = $(this).find("optgroup");
	$optgroup.each(function(index,element){
		var optionLen = $(this).find('option:selected').length;
		var $span = $ddHeader.eq(index).children("span:first-child");
		if(optionLen > 0){
			if(!$span.hasClass("glyphicon-ok")){
				$span.addClass("glyphicon-ok")
			}
		}else{
			if($span.hasClass("glyphicon-ok")){
				$span.removeClass("glyphicon-ok")
			}
		}
	})
}
function doPrint() {
    bdhtml=window.document.body.innerHTML;
    sprnstr="<!--startprint-->";
    eprnstr="<!--endprint-->";
    prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
    prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
    window.document.body.innerHTML=prnhtml;
    window.print();
    window.location.reload(); //刷新当前页面
}
function timeCount(){
	var oDateUtil = new DateUtil();
	setInterval(function(){
		var date = new Date();
		var formatDate = oDateUtil.formatDate(date,"yyyy-MM-dd hh:mm:ss",true);
		$("#timeCount").html(formatDate)
	},1000)
}	
</script>
</html>